package cn.edu.swust.adressbook.view;


import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.edu.swust.adressbook.R;

/**
 * 联系人列表
 */

public class ContactItemView extends LinearLayout implements Checkable {

    private TextView mNameText;
    private CheckBox mCheckBox;
    private TextView mHeadText;
    private final ImageView mImageView;

    public ContactItemView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.activity_contact_list_item, this, true);

        mCheckBox = (CheckBox) view.findViewById(R.id.checkbox);
        mNameText = (TextView) view.findViewById(R.id.people_name);
        mHeadText = (TextView) view.findViewById(R.id.first_word);
        mImageView = (ImageView) view.findViewById(R.id.head_image);
    }

    public void setCheckBoxVisibility(boolean visible ){
        if (visible){
            mCheckBox.setVisibility(View.VISIBLE);
            mImageView.setVisibility(GONE);
        }
        else {
            mCheckBox.setVisibility(View.GONE);
            mImageView.setVisibility(View.VISIBLE);
        }
    }

    public void setHeadTextVisible(boolean visible, char head){
        if (visible){
            mHeadText.setVisibility(View.VISIBLE);
            mHeadText.setText(String.valueOf(head));
        }
        else {
            mHeadText.setVisibility(View.GONE);
        }
    }

    @Override
    public void setChecked(boolean b) {
        mCheckBox.setChecked(b);
    }

    @Override
    public boolean isChecked() {
        return mCheckBox.isChecked();
    }

    @Override
    public void toggle() {
        mCheckBox.toggle();
    }
    public void setName(String text) {
        mNameText.setText(text);
    }

}

